import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;

/**
 * @date 2022/9/15 15:29
 * @author: Akie
 * @description: 选择一天的饭菜

 */

public class AllDay {


        public void AllDayMenu(){
            boolean isFlag = true;
            do {
                System.out.println("*******全天选餐*******");
                System.out.println();
                System.out.println("\t" + "1 随 机 安 排");
                System.out.println("\t" + "2 手 动 选 餐");
                System.out.println("\t" + "3 退      出");
                System.out.println();
                System.out.println("\t" + "请选择（1-3）：" );

                int menu = CMUtility.readMenuSelection();
                switch (menu) {
                    case '1': ChooseMealAllDayRandom();
                        break;
                    case '2': AllDayMenuByYourself();
                        break;
                    default :
                    {
                        System.out.print("确认是否退出(Y/N)：");
                        char exit = CMUtility.readConfirmSelection();
                        if (exit == 'Y') {
                            isFlag = false;
                        }
                    }
                }
            } while (isFlag);
        }

    public void AllDayMenuByYourself(){
        boolean isFlag = true;
        do {
            System.out.println("*******全天选餐*******");
            System.out.println();
            System.out.println("\t" + "1 选 择 品 种");
            System.out.println("\t" + "2 选 择 餐 厅");
            System.out.println("\t" + "3 退      出");
            System.out.println();
            System.out.println("\t" + "请选择（1-3）：" );

            int menu = CMUtility.readMenuSelection();
            switch (menu) {
                case '1': ChooseMealAllDayByYourselfWithFood();
                    break;
                case '2':ChooseMealAllDayByYourselfWithMall();
                    break;
                default :
                {
                    System.out.print("确认是否退出(Y/N)：");
                    char exit = CMUtility.readConfirmSelection();
                    if (exit == 'Y') {
                        isFlag = false;
                    }
                }
            }
        } while (isFlag);
    }

    public void ChooseMealAllDayRandom(){
        Ui ui = new Ui();
        List<Runnable> methods = new ArrayList<>();
        methods.add(ui::ChoosePie); // this is how you reference a method itself
        methods.add(ui::ChooseRice);
        methods.add(ui::ChooseNoodle);
        int randomNumber = new Random().nextInt(methods.size());
//        methods.get(randomNumber).run();

        for (int i = 0; i < 2; i++) {
            methods.get(randomNumber).run();
        }
    }

    public void ChooseMealAllDayByYourselfWithFood(){
        Ui ui = new Ui();
        System.out.println("请选择中午想吃什么类型的菜：(pie=饼,noodle=面,rice=饭)");
        Scanner scanner = new Scanner(System.in);
        String meal = scanner.next();
        if (meal.equals("pie")) {
            ui.ChoosePie();
        } else if (meal.equals("noodle")) {
            ui.ChooseNoodle();
        } else if (meal.equals("rice")) {
            ui.ChooseRice();
        } else {
            System.out.println("您的输入有误！");
        }
        System.out.println("请选择晚上想吃什么类型的菜：(pie=饼,noodle=面,rice=饭)");
        String meal1 = scanner.next();
        if (meal1.equals("pie")) {
            ui.ChoosePie();
        } else if (meal1.equals("noodle")) {
            ui.ChooseNoodle();
        } else if (meal1.equals("rice")) {
            ui.ChooseRice();
        } else {
            System.out.println("您的输入有误！");
        }
    }


    public void ChooseMealAllDayByYourselfWithMall(){
        int loopnum = 0;
        Ui ui = new Ui();
        for (int i = 0; i < 2; i++) {
            Boolean isFlag = true;
            Boolean isFlag1 = true;
            loop1:do {
                if (loopnum == 0) {
                    System.out.println("---------------------开始选择---------------------");
                    System.out.println("请选择中午想吃的食堂：（1,2,3,6,7,8=后街）");
                } else {
                    System.out.println("请选择晚上想吃的食堂：（1,2,3,6,7,8=后街）");
                }
                Scanner scanner = new Scanner(System.in);
                int input = scanner.nextInt();
                if (input == 1 || input == 2 || input == 3 || input == 6 || input == 7 || input == 8) {
                    int loop = 0;
                    if (input == 1 || input == 2 || input == 3 || input == 6 || input == 7) {
                        System.out.println("今天选择的是第" + input + "食堂");
                    }else {
                        System.out.println("今天选择的是后街");
                    }
                    do {
                        String meal = ui.ChooseMeal(input);
                        System.out.println("今天选择:" + "\t" + meal);
                        System.out.println("请输入：（Y/N）");
                        Scanner scanner1 = new Scanner(System.in);
                        String input1 = scanner.next().toUpperCase();
                        if (input1.equals("Y")) {
                            System.out.println("今天就决定是它了！" + "\t" + meal);
                            System.out.println("---------------------选择完成---------------------");
                            isFlag1 = false;
                        } else if (input1.equals("N")) {
                            loop +=1;
                            if (loop >= 4) {
                                System.out.println("是否选择其他食堂？请输入：（Y/N）");
                                String other = scanner.next().toUpperCase();
                                if (other.equals("Y")) {
                                    continue loop1;
                                } else if (other.equals("N")) {
                                    loop = 0;
                                }else {
                                    System.out.println("你的输入有误，请重新输入！");
                                }
                            }
                            System.out.println("系统将会重新选择。");
                        } else {
                            System.out.println("你的输入有误，请重新输入！");
                        }
                    } while (isFlag1);
                    isFlag = false;
                    loopnum +=1;
                }else {
                    System.out.println("您的输入有误！");
                }
            }while (isFlag);
        }



    }
}
